﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLKHO.Class;

namespace QLKHO.Forms
{
    public partial class frmPhieuNhapKho : Form
    {
        public frmPhieuNhapKho()
        {
            InitializeComponent();
            this.pHIEUNHAPKHOTableAdapter.Fill(this.qLKHODataSet.PHIEUNHAPKHO);
            clsMain.flexConn.InitForms(this.Tag.ToString(), this, qLKHODataSet.PHIEUNHAPKHO);
            clsMain.flexConn.InitForms(this.Tag.ToString(), ref fcButton1);
            clsMain.flexConn.InitForms(this.Tag.ToString(), ref dataGridView1);
            clsMain.flexConn.KhoiTaoXMLTable(this.Tag.ToString(), qLKHODataSet.PHIEUNHAPKHO);
        }

        private void frmPhieuNhapKho_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'qLKHODataSet.KHO' table. You can move, or remove it, as needed.
            this.kHOTableAdapter.Fill(this.qLKHODataSet.KHO);
            // TODO: This line of code loads data into the 'qLKHODataSet.NHANVIEN' table. You can move, or remove it, as needed.
            this.nHANVIENTableAdapter.Fill(this.qLKHODataSet.NHANVIEN);
            // TODO: This line of code loads data into the 'qLKHODataSet.CHITIETPHIEUNHAP' table. You can move, or remove it, as needed.
            this.cHITIETPHIEUNHAPTableAdapter.Fill(this.qLKHODataSet.CHITIETPHIEUNHAP);
            // TODO: This line of code loads data into the 'qLKHODataSet.HANGHOA' table. You can move, or remove it, as needed.
            this.hANGHOATableAdapter.Fill(this.qLKHODataSet.HANGHOA);
            // TODO: This line of code loads data into the 'qLKHODataSet.PHIEUNHAPKHO' table. You can move, or remove it, as needed.
            txtThanhTien.fcText = "0";

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                clsMain.flexConn.AddDataToControls(this.Tag.ToString(), e.RowIndex, qLKHODataSet.PHIEUNHAPKHO);
                butChiTiet.Enabled = true;
                clsMain.strMSPhieuNhapKho = qLKHODataSet.PHIEUNHAPKHO.Rows[e.RowIndex][0].ToString();
                butInBaoCao.Enabled = true;
            }
        }

        private void fcButton1_Click(object sender, EventArgs e)
        {
            clsMain.flexConn.ButtonsClick(this.Tag.ToString(), fcButton1.intState);
            pHIEUNHAPKHOTableAdapter.Update(qLKHODataSet.PHIEUNHAPKHO);
            if(txtThanhTien.fcText == "")
            txtThanhTien.fcText = "0";
            butChiTiet.Enabled = false;
            butInBaoCao.Enabled = false;
        }

        private void butChiTiet_Click(object sender, EventArgs e)
        {
            
            frmChiTietPhieuNhap frm = new frmChiTietPhieuNhap();
            frm.ShowDialog();
            foreach(DataRow row in qLKHODataSet.PHIEUNHAPKHO)
            {
                if(row["MASO"].ToString()==clsMain.strMSPhieuNhapKho)
                {
                    row["THANHTIEN"]=clsMain.intThanhTien;
                    pHIEUNHAPKHOTableAdapter.Update(row);
                }
            }
            
        }

        private void butInBaoCao_Click(object sender, EventArgs e)
        {
            frmReport frm = new frmReport();
            frm.Show();
        }
    }
}
